/**
 * Created by vincent on 2017/10/12.
 */
moduleStudyMap.controller("AddBadgeController", function ($$CambioConfig, $scope, $log, $state, LoadingService, EnumService,
                                                          UploadFileService, ConstantService, BadgeResource, DialogService) {
    $scope.$on("ngDialog.opened", function () {
        dialogOnLoad();
    });

    $scope.newBadge = {
        active: true
    };

    /**
     * 上传图片
     * @param $files
     */
    $scope.uploadImage = function ($files) {
        if ($files && $files[0]) {
            UploadFileService.uploadFile($files[0], $$CambioConfig.UPLOAD_URL, 'IMG', $scope).then(function (o) {
                $scope.newBadge.picture = o.id;
            });
        }
    };

    $scope.cancel = function () {
        DialogService.close();
    };

    $scope.submit = function () {
        if ($scope.addBAForm.$valid) {
            //LoadingService.show();
            BadgeResource.add($scope.newBadge, function (badgeResult) {
                $log.debug("勋章新增结果", badgeResult);
                DialogService.close();
                Alert.success("新增勋章成功！");
                //LoadingService.hide();
            });
        }
    };

});